package org.west.sky.frame.activiti.study.chapter14;

import lombok.SneakyThrows;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.west.sky.frame.activiti.study.util.ActivitiEngineUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * author: chz
 * date: 2025/3/12
 * description: 脚本任务
 */
public class RunDemo14_2 extends ActivitiEngineUtil {

    public static void main(String[] args) {
        RunDemo14_2 runDemo13_1_1 = new RunDemo14_2();
        runDemo13_1_1.deploy();
    }

    @SneakyThrows
    private void deploy() {
        loadActivitiConfigAndInitEngine("activiti.cfg.xml");
        //部署流程
        ProcessDefinition processDefinition = deployByClassPathResource("processes/chapter14/Chapter14_2.bpmn20.xml");

        Map<String, Object> variables = new HashMap<>();
        variables.put("unitPrice", 10);
        variables.put("quantity", 100);
        variables.put("inputArray", new int[]{1, 2, 3, 4, 5});
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), variables);

        List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();

        for (HistoricVariableInstance instance : list) {
            System.out.println("====变量：" + instance.getVariableName() + "的值为：" + instance.getValue());
        }
        closeEngine();
    }


}
